<?php


namespace support\traits;


trait ApiResponse
{
    public function success($data = [], $message = "操作成功", $code = 200)
    {
        return json([
            'message' => $message,
            'code' => $code,
            'data' => $data,
        ]);
    }

    public function formatPage($count, $data)
    {
        return [
            'total' => $count,
            'records' => $data,
        ];
    }

    public function error($message = "操作成功", $code = 500, $data = [])
    {
        return json([
            'message' => $message,
            'code' => $code,
            'data' => $data,
        ]);
    }
}